﻿
using System.Collections.Generic;
using System.Linq;

using Bootstrap5.Abstractions;

using Microsoft.AspNetCore.Components;

namespace Bootstrap5;

/// <summary>
/// Represents a modal dialog with a backdrop.
/// </summary>
[CssClass("modal-dialog")]
partial class Modal
{
    public Modal()
    {
    }

    [Parameter] public RenderFragment HeadContent { get; set; }
    [Parameter] public RenderFragment FootContent { get; set; }
	[Parameter] public bool Closable { get; set; } = true;
	[Parameter][CssClass("modal-dialog-scrollable")] public bool Scrollable { get; set; }
	[Parameter][CssClass("modal-dialog-centered")] public bool Centered { get; set; }
	[Parameter] [CssClass("modal-")]public ModalSize? Size { get; set; }
	[Parameter] public bool FullScreen { get; set; }
	[Parameter] public BreakPoint[] FullSreenBreakPoints  { get; set; }
	[Parameter] public bool Fade { get; set; } = true;

    protected override void OnParametersSet()
	{
		if (Trigger is not null)
		{
			foreach (var item in TriggerBuilder?.Triggers)
			{
				AdditionalAttributes.TryAdd(item.Key, item.Value);
			}
		}
	}

    protected override void CreateCssClass(ICssClassBuilder builder)
	{
		if (FullSreenBreakPoints is not null)
		{
			builder.Add(FullSreenBreakPoints.Select(m => $"modal-fullscreen{m.GetEnumCssClass("-")}-down"), FullScreen && FullSreenBreakPoints.Length > 0);
        }
        else
        {
			builder.Add($"modal-fullscreen", FullScreen);
		}
	}
}
